//
//  MKLineComicDetailView.m
//  ManKeCartoon
//
//  Created by 邹功梁 on 15/10/22.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKLineComicDetailView.h"
#import "MKBaseHeader.h"
@implementation MKLineComicDetailView

- (instancetype)initWithFrame:(CGRect)frame height:(CGFloat)height
{
    self = [super initWithFrame:frame];
    if (self) {
//        180 * HEIGHT + 80 * HEIGHT + height + 10 * HEIGHT + 60 * HEIGHT
        _comicImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180 * HEIGHT)];
//        [_comicImageView setBackgroundColor:[UIColor redColor]];
        
        _nameBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 180 * HEIGHT, SCREEN_WIDTH, 80 * HEIGHT)];
//        [_nameBackView setBackgroundColor:[UIColor yellowColor]];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50 * WIDTH, 10 * HEIGHT, 200 * WIDTH, 30 * HEIGHT)];
        [_titleLabel setTextColor:[UIColor blackColor]];
        [_titleLabel setFont:[UIFont systemFontOfSize:18.]];
//        [_titleLabel setBackgroundColor:[UIColor cyanColor]];
        
        _artist_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50 * WIDTH, 40 * HEIGHT + 10 * HEIGHT, 200 * WIDTH, 10 * HEIGHT)];
        [_artist_nameLabel setTextColor:[UIColor lightGrayColor]];
        [_artist_nameLabel setFont:[UIFont systemFontOfSize:13.]];
        
        _seq_noLabel = [[UILabel alloc] initWithFrame:CGRectMake(250 * WIDTH, 15 * HEIGHT, 30 * WIDTH, 20 * HEIGHT)];
        _seq_noLabel.layer.masksToBounds = YES;
        _seq_noLabel.layer.cornerRadius = 10 * HEIGHT;
        [_seq_noLabel setTextAlignment:NSTextAlignmentCenter];
        _seq_noLabel.textColor = [UIColor whiteColor];
        [_seq_noLabel setFont:[UIFont systemFontOfSize:13.]];
        [_seq_noLabel setBackgroundColor:[UIColor colorWithRed:0.9 green:0.32 blue:0.07 alpha:1]];
        
        
        [_nameBackView addSubview:_titleLabel];
        [_nameBackView addSubview:_artist_nameLabel];
        [_nameBackView addSubview:_seq_noLabel];
        
        // 作品介绍
        _brief_intrdLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 270 * HEIGHT, SCREEN_WIDTH - 20, height)];
        [_brief_intrdLabel setTextColor:[UIColor lightGrayColor]];
        [_brief_intrdLabel setNumberOfLines:0];
        [_brief_intrdLabel setFont:[UIFont systemFontOfSize:15.]];
//        [_brief_intrdLabel setBackgroundColor:[UIColor cyanColor]];
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 260 * HEIGHT, SCREEN_WIDTH, 1)];
        [_lineView setBackgroundColor:[UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1]];
        
        _garyLineView = [[UIView alloc] init];
        [_garyLineView setBackgroundColor:[UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1]];
        
        _orangeView = [[UIView alloc] init];
        [_orangeView setBackgroundColor:[UIColor orangeColor]];
        
        _contentLabel = [[UILabel alloc] init];
        [_contentLabel setBackgroundColor:[UIColor cyanColor]];
        [_contentLabel setFont:[UIFont systemFontOfSize:15.]];
        [_contentLabel setTextColor:[UIColor blackColor]];
        [_contentLabel setTextAlignment:NSTextAlignmentLeft];
        
        [self addSubview:_comicImageView];
        [self addSubview:_nameBackView];
        [self addSubview:_brief_intrdLabel];
        [self addSubview:_lineView];
        [self addSubview:_garyLineView];
//        [self addSubview:_orangeView];
//        [self addSubview:_contentLabel];
    }
    return self;
}

- (void)setDetailModle:(MKLightComicDetailModel *)model
{
    // UILabel设置行间距
    [_brief_intrdLabel setText:[NSString stringWithFormat:@"作品介绍:  %@", model.brief_intrd]];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_brief_intrdLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_brief_intrdLabel.text length])];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 5)];
    _brief_intrdLabel.attributedText = attributedString;
    [_brief_intrdLabel sizeToFit];
    
    [_garyLineView setFrame:CGRectMake(0, _brief_intrdLabel.frame.origin.y + _brief_intrdLabel.frame.size.height + 20, SCREEN_WIDTH, 15 * HEIGHT)];
    
    [_comicImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    
    [_contentLabel setFrame:CGRectMake(20, _garyLineView.frame.origin.y + 10 * HEIGHT, SCREEN_WIDTH -  30, 60 * HEIGHT)];
    [_contentLabel setText:@"目录"];
    
    [_orangeView setFrame:CGRectMake(0, _garyLineView.frame.origin.y + 30 * HEIGHT, 5, 20 * HEIGHT)];
    
    _titleLabel.text = model.title;
    _artist_nameLabel.text = [NSString stringWithFormat:@"作者: %@", model.artist_name];
    _seq_noLabel.text = model.lated_seqno.stringValue;
    
    [self setFrame:CGRectMake(0, 0, SCREEN_WIDTH, _contentLabel.frame.origin.y)];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
